package com.zy.explore.design.knowledge;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

/**
 * 布隆过滤器演示
 *
 * 原理：
 *
 * @author ZY
 * @date 2021/11/06
 */
public class BloomFilterDemo {

    public static void main(String[] args) {
        BloomFilter<CharSequence> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.forName("UTF-8")), 100000000, 0.0001);
        bloomFilter.put("张");
        bloomFilter.put("李");
        bloomFilter.put("王");
        System.out.println(bloomFilter.mightContain("张"));
        System.out.println(bloomFilter.mightContain("李四"));
    }

}
